package cn.com.dcsgo.settlement.calculator;

import cn.com.dcsgo.settlement.OrderAmountContext;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * 实际需要付款的金额计算器
 *
 * @author Dcsgo
 * @since 2025/11/17 18:39
 */
@Component
public class ActualPaymentMoneyCalculator extends AbstractOrderAmountCalculator {
    @Override
    public void calculate(OrderAmountContext orderAmountContext) {
        BigDecimal commoditiesAmount = orderAmountContext.getCommoditiesAmount();
        BigDecimal discountAmount = orderAmountContext.getDiscountAmount();
        BigDecimal freight = orderAmountContext.getFreight();
        orderAmountContext.setActualPaymentAmount(
                commoditiesAmount.subtract(discountAmount).add(freight)
        );
        if (getNextCalculator() != null) {
            getNextCalculator().calculate(orderAmountContext);
        }
    }
}
